<?php
/**
 * This response contains distant user's presence information
 * 
 * @package stanza.presence
 */
class Zend_Jabber_Stanza_Response_Presence extends Zend_Jabber_Stanza_Response_Abstract {
    /**
     * Get user with set presence information
     * 
     * @return Zend_Jabber_User
     */
    public function getUser() {
        $presenceNode = $this->dom->getElementsByTagName('presence')->item(0);
        $user = Zend_Jabber_User::getInstance($presenceNode->getAttribute('from'));
        
        if($showNode = $presenceNode->getElementsByTagName('show')->item(0)) {
            $user->setShow($showNode->nodeValue);
        }
        if($priorityNode = $presenceNode->getElementsByTagName('priority')->item(0)) {
            $user->setPriority((int)$priorityNode->nodeValue);
        }
        if($statusNode = $presenceNode->getElementsByTagName('status')->item(0)) {
            $user->setStatus($statusNode->nodeValue);
        }
        
        return $user;
    }
    
    /**
     * Get Response class
     * 
     * @return string
     */
    public function getClass() {
        return $this->getType();
    }
}
?>